/****************************************************************************
 * Copyright (C) 2011 Maxim Integrated Products, All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated Products
 * shall not be used except as stated in the Maxim Integrated Products
 * Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products retains all ownership rights.
 *
 *     Description: MAXQ UART driver private include file
 *             $Id: maxq_serial_priv.h 1405 2011-06-09 19:45:45Z jbrodt $
 *
 ********************************************************************************
 */

#ifndef _MAXQ_SERIAL_PRIV_H_
#define _MAXQ_SERIAL_PRIV_H_

#include "maxq_config.h"
#include "fifo\maxq_fifo.h"

#ifndef NUM_UART
#define NUM_UART  1
#endif

#if (NUM_UART == 1)
#define SCON0 SCON
#define SBUF0 SBUF
#define SMD0  SMD
#define PR0   PR
#endif


/***** Definitions *****/
// SMOD register bits
#define SERIAL_FEDE    0x01
#define SERIAL_SMOD    0x02
#define SERIAL_ESI     0x04

// SCON register bits
#define SERIAL_RI      0x01
#define SERIAL_TI      0x02
#define SERIAL_RB8     0x04
#define SERIAL_TB8     0x08
#define SERIAL_REN     0x10
#define SERIAL_SM2     0x20
#define SERIAL_SM1     0x40
#define SERIAL_SM0     0x80

typedef struct serial_port
{
  UartBaudRates currentBaudrate;  // baudrate
  SerialParity parity;    // type of parity
  uint8_t parity_err_flag;  // 1 for error, 0 for no error
  uint8_t txEnabled;  // flag to enable/disable serial transmission
  uint8_t txStatus;   // current FIFO transmission status
  fifo_t rxf;       // receive FIFO
  fifo_t txf;       // transmit FIFO
} serial_port_t;


/***** Function Prototypes *****/


/***** Global Data *****/
extern serial_port_t sp[];

static int serial_setbaud(UartBaudRates baudRate, SerialMode mode, SerialParity parity);

#endif /* _MAXQ_SERIAL_PRIV_H_ */
